<template>
  <div class="SimulationTasks-panel-table">
    <div>
      <img src="@/assets/img/other/icon-学生列表.png" class="SimulationTasks-img-Classlist-table" /><span
        class="SimulationTasks-Classlist-span-table">任务列表</span>
      <div class="Classlist-createclass-button" @click="CreateTaskDialogFn" v-show="State.Role !== '2'"><span
          class="Classlist-createclass-span">创建任务</span>
      </div>
    </div>
    <div class="SimulationTasks-panel-tablenumber">
      <el-table :data="State.StudentallInformation" style="width: 98%" height="98%" v-table-infinite-scroll="Load"
        :default-sort="{ prop: 'date', order: 'ascending' }" v-loading="State.TabLoading">
        <el-table-column prop="title" label="任务名称" min-width="22.3%" sortable>
          <template #default="scope">
            <el-form :model="scope.row">
              <el-form-item>
                <span>{{ scope.row.title }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column prop="creationTime" label="创建时间" min-width="22.3%" sortable>
          <template #default="scope">
            <el-form :model="scope.row">
              <el-form-item>
                <span>{{ dateFormats(scope.row.creationTime) }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column prop="finishCount" label="提交人数" min-width="22.3%" sortable>
          <template #default="scope">
            <el-form :model="scope.row">
              <el-form-item>
                <span>{{ scope.row.finishCount }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column fixed="right" prop="option" label="操作按钮" min-width="31.4%">
          <template #default="scope">
            <el-button class="Simulation-template-Release" v-if="scope.row.taskState == 0"
              @click="ReleaseDialog(scope.row, scope.$index)">发布</el-button>
            <el-button class="Simulation-template-Edit" v-if="scope.row.taskState == 0"
              @click="edit(scope.row, scope.$index)">编辑</el-button>
            <el-button class="Simulation-template-result" v-if="scope.row.taskState == 1 || scope.row.taskState == 2"
              @click="SimulationTasksResult(scope.row, scope.$index)">成绩</el-button>
            <el-button class="Simulation-template-finish" v-if="scope.row.taskState == 1"
              @click="FinishDialog(scope.row, scope.$index)">结束</el-button>
            <el-button class="Simulation-template-delete" v-if="scope.row.taskState == 0 || scope.row.taskState == 2"
              @click="DeleteDialog(scope.row, scope.$index)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- <div class="Simulation-el-pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="SimulationPage.currentPage"
          :page-sizes="[5,10,20,30]" 
          :page-size="SimulationPage.pagesize"        
          layout="total, sizes, prev, pager, next, jumper"
          :total="State.StudentallInformation.length">    
        </el-pagination>
      </div> -->
    </div>
    <!-- css并不好,以后需要改进 -->
    <!-- 故障 -->
    <!-- <div class="CreateTask-panel" v-if="State.typesOf == '故障诊断'"> -->
    <div class="CreateTask-panel">
      <!-- :rules="rules" 资源验证-->
      <el-dialog :title='State.SimulationTasksInformation.Taskdialogtitle'
        v-model="State.SimulationTasksInformation.Taskdialogboolean" top="5vh" @close="GetCanel"
        :close-on-click-modal="false">
        <el-form ref="ruleForm" :model="State.SimulationTasksInformation">
          <div class="CreateTask-panel-one">
            <el-form-item label="任务名称" prop="Taskname">
              <el-input class="NameIpt" v-model="State.SimulationTasksInformation.Taskname"
                autocomplete="off"></el-input>
            </el-form-item>
            <!-- <el-form-item label="参与班级">
              <el-input v-model="State.SimulationTasksInformation.ClassParticipation" autocomplete="off"
                disabled></el-input>
            </el-form-item> -->
          </div>
          <!-- =========== -->
          <div class="CreateTask-panel-two">
            <div class="title-one">实训模块</div>
            <!-- <div class="dropDown"></div> -->
            <el-select v-model="State.selectValue" class="m-2" size="large" style="width: 320px; margin-left: 12px;"
              @change="handleChange">
              <el-option v-for="item in State.selectModel" :key="item" :label="item" :value="item" />
            </el-select>

            <!-- <div class="taskType">
              <div class="title">任务类型</div>
              <div class="CreateTask-panel-two-KaoHe" style="display: flex; margin-left: 10px;">
                <div
                  :class="State.SimulationTasksInformation.SelectedTypeIndex == 1 ? 'CreateTask-panel-two-KaoHe-active' : 'CreateTask-panel-two-KaoHe-noactive'"
                  @click="ChangeselectedType(1)">训练</div>
                <div style="margin-left: 20px;"
                  :class="State.SimulationTasksInformation.SelectedTypeIndex == 2 ? 'CreateTask-panel-two-KaoHe-active' : 'CreateTask-panel-two-KaoHe-noactive'"
                  @click="ChangeselectedType(2)">考核</div>
              </div>
            </div> -->
            <div class="classTime">
              <div class="title">任务时长</div>
              <el-input v-model="State.SimulationTasksInformation.ClassParticipationtime" autocomplete="off"
                class="CreateTask-time-input" style="width: 76px; margin-left: 13px;"></el-input>
            </div>
            <el-form-item label="参与班级" class="classPart">
              <el-input v-model="State.SimulationTasksInformation.ClassParticipation" autocomplete="off"
                disabled></el-input>
            </el-form-item>
          </div>
          <!-- ================ -->
        </el-form>
        <div class="content">
          <!-- <div class="CreateTask-panel-line-one"></div>
          <div class="CreateTask-panel-line-two"></div> -->
          <div class="content-left">
            <div class="CreateTask-search-div">
              <input class="searchInput" v-model="State.SimulationTasksInformation.Search" />
              <button class="CreatSearchBtn" @click="SearchAll">
                <Search style="width: 1em; height: 1em;" />
              </button>
              <!-- <button class="resetBtn" @click="reset">重置</button> -->
            </div>
            <div class="selectModel">
              <div class="CreateTask-panel-faultcount" @click="ShowAllfault"
                :class="State.allfalutColor ? 'CreateTask-active' : ''">
                <span>全部({{ State.allFalutCount }})</span>
              </div>
              <div class="currentSelect" @click="ShowAllSelectfault"
                :class="State.selectColor ? 'CreateTask-active' : ''">
                <span>已选({{ State.SimulationTasksInformation.SelectfaultCount }})</span>
              </div>
              <div class="CreateTask-panel-faulttype">
                <el-scrollbar class="infinite-list">
                  <!-- <div class="CreateTask-faulttype-moder"
                    v-for="(its, indexs) in State.SimulationTasksInformation.AllTaskTypeName" :key="indexs"
                    @click="SelectFaultType(indexs)"
                    :class="State.SimulationTasksInformation.SelectedIndex === indexs ? 'CreateTask-active' : ''"> -->
                  <div class="CreateTask-faulttype-moder" v-for="(its, indexs) in State.SideTaskType" :key="indexs"
                    @click="SelectFaultType(its, indexs
                    )" :class="State.SimulationTasksInformation.SelectedIndex === indexs ? 'CreateTask-active' : ''">
                    <span class="CreateTask-span-name">{{ its }}({{
                      State.SimulationTasksInformation.FaultErrorCount[indexs] }})</span>
                  </div>
                </el-scrollbar>
              </div>
            </div>
            <!-- <div class="CreateTask-panel-line-three"></div> -->
          </div>
          <div class="content-right">
            <div class="CreateTask-panel-faultpoint">
              <el-scrollbar class="infinite-list">
                <!-- <div class="CreateTask-faultpoint-moder"
                  v-for="(its, indexs) in State.SimulationTasksInformation.AllTaskName" :key="indexs"
                  :class="{ 'CreateTask-fault-active': State.SimulationTasksInformation.faultSelect.indexOf(its) != -1 }"
                  @click="SelectFault(its, indexs)"> -->
                <div class="CreateTask-faultpoint-moder" v-for="(its, indexs) in State.breakdowns" :key="indexs"
                  @click="SelectFault(its, indexs)"
                  :class="{ 'CreateTask-fault-active': State.SimulationTasksInformation.faultSelect.indexOf(its) != -1 }">
                  <span class="CreateTask-fault-name">{{ its.name }}</span>
                </div>
              </el-scrollbar>
            </div>
          </div>
        </div>
        <div class="CreateTask-fault-btn">
          <!-- 编辑的确定 -->
          <el-button class="CreateTask-fault-button-one" @click="EditSimulationTasksConfirm"
            v-if="State.SimulationTasksInformation.checkEdit">确定</el-button>
          <!-- 创建的确定 -->
          <el-button class="CreateTask-fault-button-one" @click="CreateSimulationTasksConfirm"
            v-if="State.SimulationTasksInformation.checkEdit === false">确定</el-button>
          <el-button class="CreateTask-fault-button-two" @click="GetCanel">取消</el-button>
        </div>
      </el-dialog>
    </div>

    <!-- 拆装：没有已选故障 -->
    <!-- <div class="CreateTask-panel" v-if="State.typesOf == '拆装'">
      <el-dialog :title='State.SimulationTasksInformation.Taskdialogtitle'
        v-model="State.SimulationTasksInformation.Taskdialogboolean" top="5vh" @close="GetCanel"
        :close-on-click-modal="false">
        <el-form ref="ruleForm" :model="State.SimulationTasksInformation">
          <div class="CreateTask-panel-one" style="display: flex; justify-content: space-around;">
            <el-form-item label="任务名称" prop="Taskname">
              <el-input v-model="State.SimulationTasksInformation.Taskname" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="参与班级">
              <el-input v-model="State.SimulationTasksInformation.ClassParticipation" autocomplete="off"
                disabled></el-input>
            </el-form-item>
          </div>
          <div class="CreateTask-panel-two">
            <el-form-item label="任务类型">
              <div class="CreateTask-panel-two-KaoHe">
                <div
                  :class="State.SimulationTasksInformation.SelectedTypeIndex == 1 ? 'CreateTask-panel-two-KaoHe-active' : 'CreateTask-panel-two-KaoHe-noactive'"
                  @click="ChangeselectedType(1)">训练</div>
                <div
                  :class="State.SimulationTasksInformation.SelectedTypeIndex == 2 ? 'CreateTask-panel-two-KaoHe-active' : 'CreateTask-panel-two-KaoHe-noactive'"
                  @click="ChangeselectedType(2)">考核</div>
              </div>
            </el-form-item>
            <el-form-item label="任务时长">
              <el-input v-model="State.SimulationTasksInformation.ClassParticipationtime" autocomplete="off"
                class="CreateTask-time-input"></el-input>
            </el-form-item>
          </div>
        </el-form>
        <div class="CreateTask-panel-line-one"></div>
        <div class="CreateTask-panel-line-two"></div>
        <div class="CreateTask-search-div">
          <input class="searchInput" v-model="State.SimulationTasksInformation.Search" />
          <button class="CreatSearchBtn" @click="SearchAll">搜索</button>
          <button class="resetBtn" @click="reset">重置</button>
        </div>
        <div class="CreateTask-panel-faulttype DAA">
          <el-scrollbar class="infinite-list">
            <div class="CreateTask-faulttype-moder"
              v-for="(its, indexs) in State.SimulationTasksInformation.AllTaskTypeName" :key="indexs"
              @click="SelectFaultTypeDAA(indexs)"
              :class="State.SimulationTasksInformation.SelectedIndex === indexs ? 'CreateTask-active' : ''">
              <span class="CreateTask-span-name">{{ its.name
              }}({{ State.SimulationTasksInformation.FaultErrorCount[indexs] }})</span>
            </div>
          </el-scrollbar>
        </div>
        <div class="CreateTask-panel-line-three"></div>
        <div class="CreateTask-panel-faultpoint">
          <el-scrollbar class="infinite-list">
            <div class="CreateTask-faultpoint-moder" v-for="(its, indexs) in State.SimulationTasksInformation.AllTaskName"
              :key="indexs"
              :class="{ 'CreateTask-fault-active': State.SimulationTasksInformation.faultSelect.indexOf(its) != -1 }"
              @click="SelectFaultDAA(its, indexs)">
              <span class="CreateTask-fault-name">{{ its.name }}</span>
            </div>
          </el-scrollbar>
        </div>
        <div class="CreateTask-fault-btn">
          <el-button class="CreateTask-fault-button-one" @click="EditSimulationTasksConfirm"
            v-if="State.SimulationTasksInformation.checkEdit">确定</el-button>
          <el-button class="CreateTask-fault-button-one" @click="CreateSimulationTasksConfirm"
            v-if="State.SimulationTasksInformation.checkEdit === false">确定</el-button>
          <el-button class="CreateTask-fault-button-two" @click="GetCanel">取消</el-button>
        </div>
      </el-dialog>
    </div> -->

    <!-- 结束对话框 -->
    <DialogComponents :DialogComponent="FinishDialogComponent" @click="FinishSimulationTasks"></DialogComponents>
    <!-- 发布对话框 -->
    <DialogComponents :DialogComponent="ReleaseDialogComponent" @click="ReleaseSimulationTasks"></DialogComponents>
    <!-- 删除任务对话框 -->
    <DialogComponents :DialogComponent="DeleteDialogComponent" @click="DeleteSimulationTasks"></DialogComponents>
    <!-- 实训任务显示对话框 -->
    <DialogComponents :DialogComponent="ComponDialogComponent" @click="ComponDialogComponentFn"></DialogComponents>
  </div>
</template>

<script>
import router from '@/router'
import { Search } from '@element-plus/icons-vue'
import { defineComponent, reactive, watch, toRef, toRefs, onMounted, ref, nextTick } from "vue";
import { dateFormats, postData } from "@/assets/js/pubilcs.js";
import bus from "@/bus.js";
import DialogComponents from "@/components/compon/DialogComponents.vue";
import { ElMessage, ElMessageBox } from 'element-plus'
export default defineComponent({
  name: "TeacherTasksTable",
  components: {
    DialogComponents,
    Search
  },
  props: {
    StudentallInformation: {
      type: Array,
      default: "",
    },
    Taskdialogboolean: {
      type: Boolean,
      default: false,
    }
  },
  setup(props, ctx) {
    const dataList = ref(new Map());

    //无限滚动计数器
    let InfiniteScrollCount = ref(15)
    //实训任务验证
    let rules = reactive({
      Taskname: [
        {
          required: true,
          message: '请输入实训任务名称',
          trigger: 'blur',
        },
        {
          min: 1,
          max: 6,
          message: '长度只能为6字符之内',
          trigger: 'blur',
        },
      ],
    })
    //分页数据
    let SimulationPage = reactive({
      currentPage: 1,
      pagesize: 10,
    })
    let State = reactive({
      selectValue: '',
      //项目类型（是故障还是拆装）
      typesOf: '',
      selectModel: [],
      // 故障码类型
      SideTaskType: [],
      // 故障
      breakdowns: [],
      allProjects: [],
      // res.resule.resule的数据
      allData: [],
      allFalutCount: 0,
      allfalutColor: false,
      selectColor: false,

      //读取数据loaidng显示
      TabLoading: true,
      //接收实训任务数据
      StudentallInformation: [
      ],
      AllStudentallInformation: [],
      //用于接收所有的班级
      AllClass: [],
      Role: sessionStorage.getItem('role'),
      SimulationTasksInformation: {
        //实训任务标题
        Taskdialogtitle: '创建实训任务',
        //实训任务对话框显示
        Taskdialogboolean: false,
        //实训任务名称
        Taskname: '',
        //实训任务班级
        ClassParticipation: '',
        //选择实训任务类型（训练或是考核）
        SelectedTypeIndex: 1,
        //实训任务时间
        ClassParticipationtime: 30,
        //选择的实训任务个数
        SelectfaultCount: 0,
        //故障码的类型
        AllTaskTypeName: [],
        //选中的类型
        SelectedIndex: -1,
        //故障总数
        FaultErrorCount: [],
        //所有的故障类型
        AllTaskName: '',
        // 搜索的故障类型
        searchListName: '',
        //不做更新的所有的故障类型
        OldAllTaskName: '',
        //实训任务id
        TaskId: '',
        //搜索值
        Search: '',
        //选择的故障数组
        faultSelect: [],
        //判断是创建还是编辑
        checkEdit: false,
        //班级ID
        ClassId: '',
        //班级的index
        ClassIndex: 0,
        //选中行的item
        Row: '',
        //选中行的index
        RowIndex: 0,
        Classdisabled: false,
        //控制面板显示转换成成绩
        ChangePanel: 0,
      }
    })
    bus.$off('classname')
    bus.$off('classid')
    bus.$off('classindex')
    bus.$off('AllClass')

    //不同组件传值,传递班级名称
    bus.$on('classname', (data) => {
      State.SimulationTasksInformation.ClassParticipation = data
    })
    //不同组件传值,接收班级id
    bus.$on('classid', (data) => {
      State.SimulationTasksInformation.ClassId = data
    })
    //不同组件传值,接收班级的index的值
    bus.$on('classindex', (data) => {
      State.SimulationTasksInformation.ClassIndex = data
    })
    //不同组件传值,接收所有的班级
    bus.$on('AllClass', (data) => {
      State.AllClass = data
    })
    //监听父组件传过来的数据
    watch(() => props.StudentallInformation, (val, old) => {
      State.TabLoading = false
      State.StudentallInformation = []
      State.AllStudentallInformation = ExchangeData(val)
      // console.log('监听到数据改变', State.AllStudentallInformation.length, '----', InfiniteScrollCount.value);
      if (State.AllStudentallInformation.length > InfiniteScrollCount.value) {
        for (let i = 0; i < InfiniteScrollCount.value; i++) {
          State.StudentallInformation.push(State.AllStudentallInformation[i])
        }
      } else {
        for (let i = 0; i < State.AllStudentallInformation.length; i++) {
          State.StudentallInformation.push(State.AllStudentallInformation[i])
        }
      }
    },
      { deep: true }
    )
    //分页插件执行的方法
    function handleSizeChange(size) {
      SimulationPage.pagesize = size
    }
    //分页插件执行的方法
    function handleCurrentChange(currentPage) {
      SimulationPage.currentPage = currentPage
    }
    //位置互换函数
    function ExchangeData(data) {
      console.log('ExchangeData', data);
      let arr = []
      for (let i = data.length - 1; i >= 0; i--) {
        arr.push(data[i])
      }
      return arr
    }
    function Load() {
      InfiniteScrollCount.value += 7
      if (InfiniteScrollCount.value > State.AllStudentallInformation.length) {
        let count = Math.abs(State.AllStudentallInformation.length - InfiniteScrollCount.value)
        for (let i = InfiniteScrollCount.value - 7; i < InfiniteScrollCount.value - count; i++) {
          State.StudentallInformation.push(State.AllStudentallInformation[i])
        }
      } else {
        for (let i = InfiniteScrollCount.value - 7; i < InfiniteScrollCount.value; i++) {
          State.StudentallInformation.push(State.AllStudentallInformation[i])
        }
      }
      console.log("滚动到底了")
    }
    //确定创建实训任务
    function CreateSimulationTasksConfirm() {
      State.SimulationTasksInformation.SelectedTypeIndex = 2
      let CreatorUserId = sessionStorage.getItem("userid")
      let schoolId = sessionStorage.getItem("schoolId")
      let courseId = State.SimulationTasksInformation.ClassId
      let productId = sessionStorage.getItem("productId")
      let title = State.SimulationTasksInformation.Taskname
      let taskType = State.SimulationTasksInformation.SelectedTypeIndex
      let projectId = State.SimulationTasksInformation.AllfaultSelect
      let faultInfo = ''
      // let TaskModule = State.SimulationTasksInformation.AllTaskTypeName[State.SimulationTasksInformation.SelectedIndex].name
      let TaskModule = State.selectValue
      console.log('TaskModule____________', TaskModule);
      let timeLong = State.SimulationTasksInformation.ClassParticipationtime
      if (title === '' || title === null) {
        ElMessage.error('请输入实训名称')
        return
      }
      if (projectId === '' || projectId === null) {
        ElMessage.error('请选择故障点')
        return
      }
      if (timeLong === '' || timeLong === null) {
        ElMessage.error('请设定一个实训时间')
        return
      }
      postData("/api/TrainingTask/Create", JSON.stringify({
        CreatorUserId: CreatorUserId,
        schoolId: schoolId,
        courseId: courseId,
        productId: productId,
        title: title,
        taskType: taskType,
        projectId: projectId,
        faultInfo: faultInfo,
        TaskModule: TaskModule,
        timeLong: timeLong,
      }), sessionStorage.getItem("token")).
        then(function (res) {
          if (res.result.success) {
            //创建对话框消失
            State.SimulationTasksInformation.Taskdialogboolean = false
            //传递当前选择班级的index
            bus.$emit("UpdateSimulationTasks", State.SimulationTasksInformation.ClassIndex)
            //提示信息
            ElMessage({
              message: '创建成功',
              type: 'success',
            })
          } else {
            ElMessage.error('实训任务名字重复')
          }
        })
        .catch((error) => {

        });

    }
    //确定编辑实训任务
    function EditSimulationTasksConfirm() {
      let id = State.SimulationTasksInformation.TaskId
      let title = State.SimulationTasksInformation.Taskname
      let taskType = State.SimulationTasksInformation.SelectedTypeIndex
      let timeLong = State.SimulationTasksInformation.ClassParticipationtime
      // let TaskModule = State.SimulationTasksInformation.AllTaskTypeName[State.SimulationTasksInformation.SelectedIndex].name
      let TaskModule = State.selectValue
      let faultSelectString = []
      //判断当没有触发选中时，默认传人上一次的code故障代码
      for (let i = 0; i < State.SimulationTasksInformation.faultSelect.length; i++) {
        faultSelectString.push(State.SimulationTasksInformation.faultSelect[i].code)
      }
      State.SimulationTasksInformation.AllfaultSelect = faultSelectString.toString()
      let projectId = State.SimulationTasksInformation.AllfaultSelect
      console.log('projectId======', projectId);

      if (State.typesOf != '拆装' && State.typesOf != '') {
        postData("/api/TrainingTask/Update", JSON.stringify({
          id: id,
          title: title,
          taskType: taskType,
          projectId: projectId,
          timeLong: timeLong,
          taskModule: TaskModule,
        }), sessionStorage.getItem("token")).
          then(function (res) {
            console.log('不是拆装', res);
            if (res.result.success) {
              State.SimulationTasksInformation.Taskdialogboolean = false
              //传递当前选择班级的index
              bus.$emit("UpdateSimulationTasks", State.SimulationTasksInformation.ClassIndex)
              ElMessage({
                message: '编辑成功',
                type: 'success',
              })
            } else {
              ElMessage.error('实训任务名字重复')
            }
          })
          .catch((error) => {

          });
      } else {
        postData("/api/TrainingTask/Update", JSON.stringify({
          id: id,
          title: title,
          taskType: taskType,
          projectId: projectId,
          timeLong: timeLong,
          taskModule: TaskModule,
        }), sessionStorage.getItem("token")).
          then(function (res) {
            if (res.result.success) {
              State.SimulationTasksInformation.Taskdialogboolean = false
              //传递当前选择班级的index
              bus.$emit("UpdateSimulationTasks", State.SimulationTasksInformation.ClassIndex)
              ElMessage({
                message: '编辑成功',
                type: 'success',
              })
            } else {
              ElMessage.error('实训任务名字重复')
            }
          })
          .catch((error) => {

          });
      }
    }

    function edit(row, index) {
      console.log('row: ', row, 'index: ', index);
      // 点击编辑，只显示之前选择的所有故障

      //再次获得类型
      postData("/api/TeachingTask/GetAllByProduccId", JSON.stringify({ productId: sessionStorage.getItem("productId") }), sessionStorage.getItem("token")).
        then(function (res) {
          // console.log('res================', res);
          //故障类型
          State.SimulationTasksInformation.AllTaskTypeName = res.result.result
          res.result.result.forEach(el => {
            State.selectModel.push(el.module)
            if (el.module == row.taskModule) {
              State.SideTaskType = el.systems
            }
            State.allProjects.push(el.projectGroups)
          });
          // SelectFaultType(State.SideTaskType[0]) 
          ShowAllSelectfault()
          let allfalut = []
          for (let i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++) {
            if (row.taskModule == State.SimulationTasksInformation.AllTaskTypeName[i].module) {
              for (let j = 0; j < State.SimulationTasksInformation.AllTaskTypeName[i].projectGroups.length; j++) {
                allfalut.push(State.SimulationTasksInformation.AllTaskTypeName[i].projectGroups[j])
                State.allFalutCount = allfalut.length
              }
            }
          }


          // for(let i = 0; i < res.result.result.length; i++) {
          //   State.taskModule = res.result.result[i].module
          //   // if(row.taskModule == res.result.result[i].module) {
          //     // State.SimulationTasksInformation.AllTaskTypeName.push(res.result.result[i])
          //     // console.log('State.SimulationTasksInformation.AllTaskTypeName', State.SimulationTasksInformation.AllTaskTypeName);
          //     State.allFalutCount = State.SimulationTasksInformation.AllTaskTypeName[0].projectGroups.length  // 全部故障的数量
          //     State.SideTaskType = State.SimulationTasksInformation.AllTaskTypeName[0].systems  // 左侧故障码的类型（拆卸、安装）
          //   // }
          // }
          State.typesOf = Object.keys(res.result.result)[0]  // 需要么？？？？
          //重新赋值编辑取值数组
          //临时储存数组
          let alltaskname = []
          for (var i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++) {
            for (var j = 0; j < State.SimulationTasksInformation.AllTaskTypeName[i].projectGroups.length; j++) {
              alltaskname.push(State.SimulationTasksInformation.AllTaskTypeName[i].projectGroups[j])
            }
          }
          //不做更新的故障类型的故障点
          State.SimulationTasksInformation.OldAllTaskName = alltaskname

          EditSimulationTasks(row, index)
          // if (State.typesOf != '拆装' && State.typesOf != '') {
          //   EditSimulationTasks(row, index)
          // } else {
          //   EditSimulationTasksDAA(row, index)
          // }
        })
        .catch((error) => {
          console.log(error)
        });
    }
    //编辑实训任务拆装
    function EditSimulationTasksDAA(row, index) {
      State.SimulationTasksInformation.SelectedIndex = null
      console.log('拆装编辑的row', row, index);
      //显示对话框
      State.SimulationTasksInformation.Taskdialogboolean = true
      //实训任务ID
      State.SimulationTasksInformation.TaskId = row.id
      //改变标题
      State.SimulationTasksInformation.Taskdialogtitle = "编辑实训任务"
      //显示实训任务名称
      State.SimulationTasksInformation.Taskname = row.title
      //显示实训任务类型
      State.SimulationTasksInformation.SelectedTypeIndex = row.taskType
      //显示实训任务时间
      State.SimulationTasksInformation.ClassParticipationtime = row.timeLong
      //切割的错误code代码?????????
      let codearr = row.projectId.split(",")
      //临时储存
      let projectsarr = []
      // console.log('===========================',State.SimulationTasksInformation.AllTaskTypeName);
      // State.SimulationTasksInformation.AllTaskTypeName.forEach((item, index) => {
      //   if (item.name == row.taskModule) {
      //     item.projects.forEach((j, indexs) => {
      //       for (let i = 0; i < codearr.length; i++) {
      //         if (codearr[i] === j.code) {
      //           projectsarr.push(j)
      //         }
      //       }
      //     });
      //     State.SimulationTasksInformation.SelectedIndex = index
      //     State.SimulationTasksInformation.FaultErrorCount[index] = projectsarr.length
      //     console.log('projectsarr.length', projectsarr.length);
      //   }
      // });
      // //防止创建编辑没点确定的时候都加入进去
      // State.SimulationTasksInformation.faultSelect = projectsarr
      // //显示故障类型
      // State.SimulationTasksInformation.AllTaskName = projectsarr
      // //显示故障码的总数量
      // State.SimulationTasksInformation.SelectfaultCount = State.SimulationTasksInformation.faultSelect.length
      // //显示编辑按钮
      // State.SimulationTasksInformation.checkEdit = true
      // ====================================================================================
      //防止创建编辑没点确定的时候都加入进去
      State.SimulationTasksInformation.faultSelect = []
      for (let i = 0; i < codearr.length; i++) {
        for (let j = 0; j < State.SimulationTasksInformation.OldAllTaskName.length; j++) {
          if (codearr[i] === State.SimulationTasksInformation.OldAllTaskName[j].code) {
            projectsarr.push(State.SimulationTasksInformation.OldAllTaskName[j])
            State.SimulationTasksInformation.faultSelect.push(State.SimulationTasksInformation.OldAllTaskName[j])
          }
        }
      }
      //统计故障码的数量
      for (let i = 0; i < State.SimulationTasksInformation.faultSelect.length; i++) {
        for (let j = 0; j < State.SimulationTasksInformation.AllTaskTypeName.length; j++) {
          if (State.SimulationTasksInformation.faultSelect[i].system === State.SimulationTasksInformation.AllTaskTypeName[j].name) {
            State.SimulationTasksInformation.FaultErrorCount[j] += 1
          }
        }
      }
      //显示故障类型
      State.SimulationTasksInformation.AllTaskName = projectsarr
      //显示故障码的总数量
      State.SimulationTasksInformation.SelectfaultCount = State.SimulationTasksInformation.faultSelect.length
      //显示编辑按钮
      State.SimulationTasksInformation.checkEdit = true
      // ====================================================================================
    }
    //编辑实训任务
    function EditSimulationTasks(row, index) {
      console.log('编辑实训任务的row: ', row, 'index: ', index);
      //显示对话框
      State.SimulationTasksInformation.Taskdialogboolean = true
      //实训任务ID
      State.SimulationTasksInformation.TaskId = row.id
      //改变标题
      State.SimulationTasksInformation.Taskdialogtitle = "编辑实训任务"
      //显示实训任务名称
      State.SimulationTasksInformation.Taskname = row.title
      //显示实训任务类型
      State.SimulationTasksInformation.SelectedTypeIndex = row.taskType
      //显示实训任务时间
      State.SimulationTasksInformation.ClassParticipationtime = row.timeLong
      // 显示实训模块
      State.selectValue = row.taskModule
      //切割的错误code代码
      let codearr = row.projectId.split(",")

      //临时储存
      let projectsarr = []
      //防止创建编辑没点确定的时候都加入进去
      State.SimulationTasksInformation.faultSelect = []

      // console.log('111111111111111111111', State.SimulationTasksInformation.OldAllTaskName);
      // console.log('222222222222222222222',codearr);

      //寻找出相同的错误对象加入数组，然后显示出来
      for (let i = 0; i < codearr.length; i++) {
        for (let j = 0; j < State.SimulationTasksInformation.OldAllTaskName.length; j++) {
          if (codearr[i] === State.SimulationTasksInformation.OldAllTaskName[j].code) {
            projectsarr.push(State.SimulationTasksInformation.OldAllTaskName[j])
            if (State.selectValue == State.SimulationTasksInformation.OldAllTaskName[j].type) {
              State.SimulationTasksInformation.faultSelect.push(State.SimulationTasksInformation.OldAllTaskName[j])
            }
          }
        }
      }
      //统计故障码的数量
      console.log('State.SimulationTasksInformation.faultSelect', State.SimulationTasksInformation.faultSelect);
      State.breakdowns = State.SimulationTasksInformation.faultSelect
      console.log('点击编辑---State.breakdowns', State.breakdowns);
      console.log('State.SimulationTasksInformation.AllTaskTypeName', State.SimulationTasksInformation.AllTaskTypeName);
      console.log(State.SideTaskType, 'biaoqian');

      State.SideTaskType.forEach((item, index) => {
        // State.SimulationTasksInformation.FaultErrorCount.push(0)
        State.SimulationTasksInformation.FaultErrorCount[index] = 0
      });

      State.SimulationTasksInformation.faultSelect.forEach(item => {
        for (let i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++) {
          for (let j = 0; j < State.SimulationTasksInformation.AllTaskTypeName[i].systems.length; j++) {
            if (item.system === State.SimulationTasksInformation.AllTaskTypeName[i].systems[j]) {
              if (State.SimulationTasksInformation.AllTaskTypeName[i].multiSelect) {
                if (State.SimulationTasksInformation.FaultErrorCount[j] < 10) {
                  State.SimulationTasksInformation.FaultErrorCount[j] += 1
                }
              } else {
                if (State.SimulationTasksInformation.FaultErrorCount[j] < 1) {
                  State.SimulationTasksInformation.FaultErrorCount[j] += 1
                }
              }
            }
          }
        }
      });
      // console.log('State.SimulationTasksInformation.faultSelect', State.SimulationTasksInformation.faultSelect);
      // console.log('State.SimulationTasksInformation.AllTaskTypeName', State.SimulationTasksInformation.AllTaskTypeName);
      // for (let i = 0; i < State.SimulationTasksInformation.faultSelect.length; i++) {
      //   for (let j = 0; j < State.SimulationTasksInformation.AllTaskTypeName.length; j++) {
      //     if (State.SimulationTasksInformation.faultSelect[i].system === State.SimulationTasksInformation.AllTaskTypeName[j].name) {
      //       State.SimulationTasksInformation.FaultErrorCount[j] += 1
      //       console.log('@@@@@@@@@@@@@@@@@@@@', State.SimulationTasksInformation.FaultErrorCount);
      //     }
      //   }
      // }
      console.log('State.SimulationTasksInformation.FaultErrorCount', State.SimulationTasksInformation.FaultErrorCount);
      //显示故障类型
      State.SimulationTasksInformation.AllTaskName = projectsarr
      //显示故障码的总数量
      State.SimulationTasksInformation.SelectfaultCount = State.SimulationTasksInformation.faultSelect.length
      //显示编辑按钮
      State.SimulationTasksInformation.checkEdit = true
    }
    function handleChange(value) {
      State.selectColor = false
      State.allfalutColor = false
      State.SimulationTasksInformation.faultSelect = []
      State.SimulationTasksInformation.SelectfaultCount = 0
      for (let i = 0; i < State.SimulationTasksInformation.FaultErrorCount.length; i++) {
        State.SimulationTasksInformation.FaultErrorCount[i] = 0
      }
      State.SimulationTasksInformation.AllfaultSelect = ''
      State.SimulationTasksInformation.Search = ''

      let allfalut = []
      for (let i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++) {
        if (State.selectValue == State.SimulationTasksInformation.AllTaskTypeName[i].module) {
          for (let j = 0; j < State.SimulationTasksInformation.AllTaskTypeName[i].projectGroups.length; j++) {
            allfalut.push(State.SimulationTasksInformation.AllTaskTypeName[i].projectGroups[j])
            State.allFalutCount = allfalut.length
          }
        }
      }
      State.SimulationTasksInformation.AllTaskTypeName.forEach(ele => {
        if (ele.module == value) {
          State.SideTaskType = ele.systems
          SelectFaultType(ele.systems[0])
          State.SimulationTasksInformation.SelectedIndex = 0
        }
      });
    }
    //获取所有实训任务（点击创建任务）
    async function GetAllSimulationTasks() {
      await postData("/api/TeachingTask/GetAllByProduccId", JSON.stringify({ productId: sessionStorage.getItem("productId") }), sessionStorage.getItem("token")).
        then(function (res) {
          console.log('获取所有实训任务', res);
          console.log('State.SimulationTasksInformation', State.SimulationTasksInformation);
          State.allData.push(res.result.result)
          //故障类型
          State.SimulationTasksInformation.AllTaskTypeName = res.result.result
          State.typesOf = Object.keys(res.result.result)[0]
          res.result.result.forEach(el => {
            State.selectModel.push(el.module)
            State.selectValue = State.selectModel[0]
            State.SideTaskType = el.systems
            State.allProjects.push(el.projectGroups)
          });
          let allfalut = []
          for (let i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++) {
            if (State.selectValue == State.SimulationTasksInformation.AllTaskTypeName[i].module) {
              for (let j = 0; j < State.SimulationTasksInformation.AllTaskTypeName[i].projectGroups.length; j++) {
                allfalut.push(State.SimulationTasksInformation.AllTaskTypeName[i].projectGroups[j])
                State.allFalutCount = allfalut.length
              }
            }
          }
          // for(let i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++){
          //   if(State.selectValue == State.SimulationTasksInformation.AllTaskTypeName[i].module) {
          //     State.allFalutCount = State.SimulationTasksInformation.AllTaskTypeName[i].projectGroups[0].length
          //   }
          // }

          handleChange(State.selectModel[0])
          SelectFaultType(State.SideTaskType[0])
          console.log('State.typesOf', State.typesOf);
          //故障码的数量
          for (let i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++) {
            for (let j = 0; j < State.SimulationTasksInformation.AllTaskTypeName[i].systems.length; j++) {
              State.SimulationTasksInformation.FaultErrorCount[j] = 0
            }
          }
          //临时储存数组
          let alltaskname = []
          // for (var i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++) {
          //   for (var j = 0; j < State.SimulationTasksInformation.AllTaskTypeName[i].projects.length; j++) {
          //     alltaskname.push(State.SimulationTasksInformation.AllTaskTypeName[i].projects[j])
          //   }
          // }
          // for (const [key, value] of Object.entries(res.result.result)) {
          //     console.log('111111111111111111111111111111',`${key}`,value);
          //     dataList.value.set(key,value);
          // }
          // const myArray = Array.from(dataList.value);
          // console.log('+++++++++++++++++++++++++++',myArray);
          // if (State.typesOf == '故障诊断') {
          //   let newData = res.result.result.故障诊断.projectGroups
          //   console.log(newData);
          //   State.SimulationTasksInformation.AllTaskName = Object.keys(newData)
          //   console.log('===============',State.SimulationTasksInformation.AllTaskName);
          // }
          //故障类型的故障点
          // State.SimulationTasksInformation.AllTaskName = res.result.result
          // console.log('故障类型的故障点33333AllTaskName: ',State.SimulationTasksInformation.AllTaskName);
          //不做更新的故障类型的故障点
          State.SimulationTasksInformation.OldAllTaskName = alltaskname
          //选择的故障类型
          State.SimulationTasksInformation.SelectedIndex = 0
        })
    }
    //取消通用函数
    function ComGetCanel() {
      //实训任务名称
      State.SimulationTasksInformation.Taskname = ''
      //选择的故障类型
      State.SimulationTasksInformation.faultSelect = [],
        //选中的故障总数
        State.SimulationTasksInformation.SelectfaultCount = 0
      // 所有的故障数
      State.allFalutCount = 0
      State.selectValue = ''
      State.SideTaskType = [],
        //存入所有选中的选中(code)
        State.SimulationTasksInformation.AllfaultSelect = ''
      //存入所有选中的选中(名字)
      State.SimulationTasksInformation.AllfaultName = ""
      //选择的样式恢复默认
      State.SimulationTasksInformation.SelectedIndex = -1
      //故障类型
      State.SimulationTasksInformation.SelectedTypeIndex = 1
      //设置所有的故障为0
      for (let i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++) {
        State.SimulationTasksInformation.FaultErrorCount[i] = 0
      }
      State.SimulationTasksInformation.AllTaskTypeName = []
      //显示创建按钮
      State.SimulationTasksInformation.checkEdit = false

    }
    //取消对话框
    function GetCanel() {
      State.selectModel = []
      State.allProjects = []
      State.breakdowns = []
      State.selectColor = false
      State.allfalutColor = false

      //对话框取消
      State.SimulationTasksInformation.Taskdialogboolean = false
      ComGetCanel()
      setTimeout(() => {
        State.SimulationTasksInformation.ClassParticipationtime = 30
      }, 500);
    }
    //选择故障总数
    function SelectFault(value) {
      console.log('选择故障的value: ', value);
      console.log('State.SimulationTasksInformation', State.SimulationTasksInformation);
      // 如果里面有这一条，就循环出来，减去
      if (State.SimulationTasksInformation.faultSelect.indexOf(value) !== -1) {
        for (let i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++) {
          for (let j = 0; j < State.SimulationTasksInformation.AllTaskTypeName[i].systems.length; j++) {
            if (value.system === State.SimulationTasksInformation.AllTaskTypeName[i].systems[j]) {
              State.SimulationTasksInformation.FaultErrorCount[j] -= 1
              State.SimulationTasksInformation.faultSelect.splice(State.SimulationTasksInformation.faultSelect.indexOf(value), 1);
            }
          }
        }
      } else {
        for (let i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++) {
          for (let j = 0; j < State.SimulationTasksInformation.AllTaskTypeName[i].systems.length; j++) {
            if (value.system === State.SimulationTasksInformation.AllTaskTypeName[i].systems[j]) {
              if (State.SimulationTasksInformation.AllTaskTypeName[i].multiSelect) {
                if (State.SimulationTasksInformation.FaultErrorCount[j] < 10) {
                  State.SimulationTasksInformation.FaultErrorCount[j] += 1
                  State.SimulationTasksInformation.faultSelect.push(value);
                } else if (State.SimulationTasksInformation.FaultErrorCount[j] >= 10) {
                  ElMessage.error('该故障类型最多只能选取10个故障')
                }
              } else {
                if (State.SimulationTasksInformation.FaultErrorCount[j] < 1) {
                  State.SimulationTasksInformation.FaultErrorCount[j] += 1
                  State.SimulationTasksInformation.faultSelect.push(value);
                } else if (State.SimulationTasksInformation.FaultErrorCount[j] >= 1) {
                  ElMessage.error('该故障类型最多只能选取1个故障')
                }
              }
            }
          }
        }
      }
      //临时储存故障点的code 
      let faultSelectString = []
      for (var i = 0; i < State.SimulationTasksInformation.faultSelect.length; i++) {
        faultSelectString.push(parseInt(State.SimulationTasksInformation.faultSelect[i].code))
      }
      State.SimulationTasksInformation.SelectfaultCount = State.SimulationTasksInformation.faultSelect.length
      //存入所有选中的选中(code)
      State.SimulationTasksInformation.AllfaultSelect = faultSelectString.toString()

      console.log('11111111111', State.SimulationTasksInformation.faultSelect);
    }

    //选择故障总数
    function SelectFaultDAA(value) {
      if (State.SimulationTasksInformation.faultSelect.indexOf(value) !== -1) {
        for (let i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++) {
          if (value.system === State.SimulationTasksInformation.AllTaskTypeName[i].name) {
            State.SimulationTasksInformation.FaultErrorCount[i] -= 1
            State.SimulationTasksInformation.faultSelect.splice(State.SimulationTasksInformation.faultSelect.indexOf(value), 1);
          }
        }
      } else {
        for (let i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++) {
          if (value.system === State.SimulationTasksInformation.AllTaskTypeName[i].name) {
            State.SimulationTasksInformation.FaultErrorCount[i] += 1
            State.SimulationTasksInformation.faultSelect.push(value);
          }
        }
      }
      //临时储存故障点的code 
      let faultSelectString = []
      for (var i = 0; i < State.SimulationTasksInformation.faultSelect.length; i++) {
        faultSelectString.push(parseInt(State.SimulationTasksInformation.faultSelect[i].code))
      }
      State.SimulationTasksInformation.SelectfaultCount = State.SimulationTasksInformation.faultSelect.length
      //存入所有选中的选中(code)
      State.SimulationTasksInformation.AllfaultSelect = faultSelectString.toString()
    }

    //选择故障类型
    function SelectFaultType(item, indexs) {
      console.log('item: ', item, 'index: ', indexs);
      State.selectColor = false
      State.allfalutColor = false
      sessionStorage.setItem('indexs', indexs)
      // //选择的样式
      State.SimulationTasksInformation.SelectedIndex = indexs
      // //所有的种类
      // State.SimulationTasksInformation.AllTaskName = State.SimulationTasksInformation.AllTaskTypeName[indexs].projects
      State.breakdowns = []
      State.allProjects.forEach(ele => {
        ele.forEach(element => {
          if (element.system == item) {
            State.breakdowns.push(element)
          }
        });
      });
    }


    //选择故障类型
    function SelectFaultTypeDAA(indexs) {
      sessionStorage.setItem('indexDAA', indexs)
      //清空
      // State.SimulationTasksInformation.faultSelect = []
      //设置所有的故障为0
      // for (let i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++) {
      //   State.SimulationTasksInformation.FaultErrorCount[i] = 0
      // }
      //选择的样式
      State.SimulationTasksInformation.SelectedIndex = indexs
      //所有的种类
      State.SimulationTasksInformation.AllTaskName = State.SimulationTasksInformation.AllTaskTypeName[indexs].projects
    }
    // 显示所有故障
    function ShowAllfault() {
      State.allfalutColor = true
      State.selectColor = false
      console.log('点击了全部故障');
      let allfalut = []
      for (let i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++) {
        if (State.selectValue == State.SimulationTasksInformation.AllTaskTypeName[i].module) {
          for (let j = 0; j < State.SimulationTasksInformation.AllTaskTypeName[i].projectGroups.length; j++) {
            allfalut.push(State.SimulationTasksInformation.AllTaskTypeName[i].projectGroups[j])
            State.allFalutCount = allfalut.length
          }
        }
      }
      State.breakdowns = allfalut
    }
    // 显示所有已选故障
    function ShowAllSelectfault() {
      State.selectColor = true
      State.allfalutColor = false
      console.log('点击了已选');
      let projectsarr = []
      for (let i = 0; i < State.SimulationTasksInformation.faultSelect.length; i++) {
        projectsarr.push(State.SimulationTasksInformation.faultSelect[i])
      }
      // State.SimulationTasksInformation.AllTaskName = projectsarr
      State.breakdowns = projectsarr
      //显示所有已选故障总数
      State.SimulationTasksInformation.SelectfaultCount = State.SimulationTasksInformation.faultSelect.length
    }

    //搜索所有故障（搜索的是全部里的故障）
    function SearchAll() {
      console.log('点击了搜索');
      let data = [];
      for (let i = 0; i < State.SimulationTasksInformation.AllTaskTypeName.length; i++) {
        if (State.selectValue == State.SimulationTasksInformation.AllTaskTypeName[i].module) {
          for (let j = 0; j < State.SimulationTasksInformation.AllTaskTypeName[i].projectGroups.length; j++) {
            if (State.SimulationTasksInformation.AllTaskTypeName[i].projectGroups[j].name.indexOf(State.SimulationTasksInformation.Search) !== -1) {
              data.push(State.SimulationTasksInformation.AllTaskTypeName[i].projectGroups[j]);
            }
          }
        }
      }
      State.breakdowns = []
      data.forEach(item => {
        State.breakdowns.push(item)
      });
      // for (let i = 0; i < State.SimulationTasksInformation.AllTaskName.length; i++) {

      //   if (State.SimulationTasksInformation.AllTaskName[i].name.indexOf(State.SimulationTasksInformation.Search) !== -1) {
      //     data.push(State.SimulationTasksInformation.AllTaskName[i]);
      //   }
      // }
      // State.SimulationTasksInformation.AllTaskName = []
      // data.forEach(item => {
      //   State.SimulationTasksInformation.AllTaskName.push(item)
      // });
      if (!State.SimulationTasksInformation.Search) {
        ElMessageBox.alert('请输入搜索内容', '提示', {
          confirmButtonText: 'OK',
        })
      }
      // State.SimulationTasksInformation.AllTaskName.filter((item: any) => {
      //   return item.name.includes(State.SimulationTasksInformation.Search)
      // })

    }
    // 重置
    function reset() {
      // postData("/api/TeachingTask/GetAllByProduccId", JSON.stringify({ productId: sessionStorage.getItem("productId") }), sessionStorage.getItem("token")).
      //   then(function (res) {
      //     console.log('点击的重置: ', res);
      //     //故障类型
      //     // State.SimulationTasksInformation.AllTaskTypeName = res.result.result
      //     State.SimulationTasksInformation.AllTaskName = res.result.result[parseInt(sessionStorage.getItem('indexs'))].projects
      //   })
      // // State.SimulationTasksInformation.SelectedIndex = parseInt(sessionStorage.getItem('indexs'))
      if (State.typesOf != '拆装' && State.typesOf != '') {
        SelectFaultType(parseInt(sessionStorage.getItem('indexs')))
      } else {
        SelectFaultTypeDAA(parseInt(sessionStorage.getItem('indexDAA')))
      }

      State.SimulationTasksInformation.Search = ''
    }
    //选择实训任务的类型
    function ChangeselectedType(number) {
      //选中的故障类型(训练/考核)
      State.SimulationTasksInformation.SelectedTypeIndex = number
    }
    //没有激活产品时的提示(通用对话框)
    let ComponDialogComponent = reactive({
      Dialogboolean: false,
      Msg: "请先激活该产品!",
      Speanstyles: {

      },
      Buttonstyle: {
        background: 'linear-gradient(-90deg, #0974D8, #3D8EF1, #7C7FF8)'
      },
      Buttonname: "确定",
    })
    //通用对话框（创建任务）
    function CreateTaskDialogFn() {
      State.typesOf = ''


      if (sessionStorage.getItem('productId') === '99999') {
        ComponDialogComponent.Dialogboolean = true
      } else if (State.AllClass.length === 0) {
        ComponDialogComponent.Dialogboolean = true
        ComponDialogComponent.Msg = "请先创建班级"
      } else {  // 有班级可以创建的情况
        //选择故障总数（获取所有实训任务）
        State.SimulationTasksInformation.AllTaskName = []
        GetAllSimulationTasks()
        //情况所有的信息
        ComGetCanel()
      }
      State.SimulationTasksInformation.Taskdialogboolean = true
    }

    function ComponDialogComponentFn(fn) {
      if (fn === 'Cancel') {
        ComponDialogComponent.Dialogboolean = false
      }
      if (fn === 'Ready') {
        ComponDialogComponent.Dialogboolean = false
      }
    }
    //结束实训任务
    function FinishDialog(row, indexs) {
      FinishDialogComponent.Dialogboolean = true
      State.SimulationTasksInformation.Row = row
      State.SimulationTasksInformation.RowIndex = indexs
    }
    //结束实训任务数据
    let FinishDialogComponent = reactive({
      Dialogboolean: false,
      Msg: "是否结束此实训任务",
      Speanstyles: {

      },
      Buttonstyle: {
        background: '#BF3434'
      },
      Buttonname: "确定",
    })
    function FinishSimulationTasks(fn) {
      if (fn === 'Cancel') {
        FinishDialogComponent.Dialogboolean = false
      }
      if (fn === 'Ready') {
        postData("/api/TrainingTask/Finish", JSON.stringify({ id: State.SimulationTasksInformation.Row.id }), sessionStorage.getItem("token")).
          then(function (res) {
            State.StudentallInformation[State.SimulationTasksInformation.RowIndex].taskState = "2"
            ElMessage({
              message: '结束成功',
              type: 'success',
            })
            FinishDialogComponent.Dialogboolean = false
          })
          .catch((error) => {
            console.log(error)
          });
      }
    }
    //发布实训任务
    function ReleaseDialog(row, indexs) {
      ReleaseDialogComponent.Dialogboolean = true
      State.SimulationTasksInformation.Row = row
      State.SimulationTasksInformation.RowIndex = indexs
    }
    //发布实训数据
    let ReleaseDialogComponent = reactive({
      Dialogboolean: false,
      Msg: "是否发布此实训任务",
      Speanstyles: {

      },
      Buttonstyle: {
        background: 'linear-gradient(-90deg, #0974d8, #3d8ef1, #7c7ff8)'
      },
      Buttonname: "确定",
    })
    function ReleaseSimulationTasks(fn) {
      if (fn === 'Cancel') {
        ReleaseDialogComponent.Dialogboolean = false
      }
      if (fn === 'Ready') {
        postData("/api/TrainingTask/Release", JSON.stringify({ id: State.SimulationTasksInformation.Row.id }), sessionStorage.getItem("token")).
          then(function (res) {
            console.log('发布', res);  // res为空
            if (res.result.success) {
              State.StudentallInformation[State.SimulationTasksInformation.RowIndex].taskState = "1"
              ElMessage({
                message: '发布成功',
                type: 'success',
              })
              ReleaseDialogComponent.Dialogboolean = false
            }
          })
          .catch((error) => {
            console.log(error)
          });
      }
    }
    //删除实训任务
    function DeleteDialog(row, indexs) {
      DeleteDialogComponent.Dialogboolean = true
      State.SimulationTasksInformation.Row = row
      State.SimulationTasksInformation.RowIndex = indexs
    }
    //删除实训任务数据
    let DeleteDialogComponent = reactive({
      Dialogboolean: false,
      Msg: "是否删除此实训任务",
      Speanstyles: {

      },
      Buttonstyle: {
        background: '#BF3434'
      },
      Buttonname: "确定",
    })
    //删除实训任务
    function DeleteSimulationTasks(fn) {
      if (fn === 'Cancel') {
        DeleteDialogComponent.Dialogboolean = false
      }
      if (fn === 'Ready') {
        postData("/api/TrainingTask/Delete", JSON.stringify({ id: State.SimulationTasksInformation.Row.id }), sessionStorage.getItem("token")).
          then(function (res) {
            if (res.result.success) {
              //移除数据
              State.StudentallInformation.splice(State.SimulationTasksInformation.RowIndex, 1);
              ElMessage({
                message: '删除成功',
                type: 'success',
              })
              DeleteDialogComponent.Dialogboolean = false
            }
          })
          .catch((error) => {
            console.log(error)
          });
      }
    }
    //实训任务成绩
    function SimulationTasksResult(row) {
      postData("/api/TaskManage/GetResultByTrainingTaskId", JSON.stringify({ TrainingTaskId: row.id, CourseId: row.courseId }), sessionStorage.getItem("token")).
        // postData("/api/TaskManage/GetResultByTrainingTaskId",JSON.stringify({TrainingTaskId:81,CourseId:386}),sessionStorage.getItem("token")).
        then(function (res) {
          console.log('实训任务成绩',res)
          if (res.result.success) {
            let newtype = sessionStorage.getItem('productTypeId')
            let parameter = []
            parameter.push({
              SetAllResult: res.result.result.taskGroup,
              Panel: 'Teacher',
              ChangePanel: 1,
              type: newtype,
              Breadcrumbs: [
                {
                  pathname: '实训任务',
                  path: '/SimulationTasks'
                },
                {
                  pathname: '实训成绩',
                  path: '/SimulationTasks'
                }
              ]
            })
            ctx.emit("GetChangePanel", parameter)
          }
        })
        .catch((error) => {
          console.log(error)
        });

      // router.push({
      //   name: 'ResuAll',
      // });

    }
    onMounted(() => {
      //获取所有实训任务(弊端,如果实训任务更新了，必须刷新页面一次才能获取最新的数据)
      // GetAllSimulationTasks()
    });
    return {
      State,
      FinishDialog,
      FinishDialogComponent,
      FinishSimulationTasks,
      ReleaseDialog,
      ReleaseDialogComponent,
      ReleaseSimulationTasks,
      DeleteDialog,
      DeleteDialogComponent,
      DeleteSimulationTasks,
      SimulationTasksResult,
      EditSimulationTasks,
      ChangeselectedType,
      SearchAll,
      SelectFaultType,
      SelectFault,
      dateFormats,
      GetAllSimulationTasks,
      handleChange,
      GetCanel,
      ShowAllfault,
      ShowAllSelectfault,
      CreateSimulationTasksConfirm,
      rules,
      EditSimulationTasksConfirm,
      ComponDialogComponent,
      CreateTaskDialogFn,
      ComponDialogComponentFn,
      Load,
      SimulationPage,
      handleSizeChange,
      handleCurrentChange,
      SelectFaultDAA,
      SelectFaultTypeDAA,
      edit,
      EditSimulationTasksDAA,
      reset,
    };
  },
});
</script>
<style lang="less" scoped>
.searchInput {
  width: 222px;
  height: 42px;
  border-radius: 5px;
  border: 1px solid #dcdfe6;
  outline: none;
  text-align: center;
}

.CreatSearchBtn {
  width: 42px;
  height: 42px;
  color: white;
  border: none;
  border-radius: 5px;
  background-color: #0974d8;
  font-size: 21px;
  padding-top: 6px;
}

.resetBtn {
  width: 60px;
  height: 40px;
  position: absolute;
  top: -4px;
  left: 183px;
  color: white;
  border: none;
  border-radius: 5px;
  background-color: #0974d8;
}

/* 表格大小*/
.SimulationTasks-panel-table {
  position: absolute;
  width: 1360px;
  height: calc(100% - 290px);
  left: 520px;
  top: 280px;
  background: #ffffff;
  border-radius: 16px;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -o-user-select: none;
}

.SimulationTasks-img-Classlist-table {
  position: absolute;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  left: 19px;
  top: 19px;
}

.SimulationTasks-Classlist-span-table {
  position: absolute;
  left: 0px;
  top: 18px;
  width: 180px;
  height: 24px;
  font-size: 18px;
  color: #81859c;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #81859c;
}

/* 表格位置 */
.SimulationTasks-panel-tablenumber {
  position: absolute;
  left: 20px;
  top: 60px;
  width: 1340px;
  height: calc(100% - 60px);
}

/* 弹出框的宽高度 */
.SimulationTasks-panel-tablenumber .el-dialog {
  width: 640px;
  height: calc(100% - 60px);
}

/* 子元素居中 */
.SimulationTasks-panel-tablenumber .dialog-footer {
  text-align: center;
}

/* 表格数据居中 */
/deep/.SimulationTasks-panel-tablenumber .cell {
  text-align: center;
}

.SimulationTasks-panel-tablenumber .el-form-item {
  margin-bottom: 0px;
}

.SimulationTasks-panel-tablenumber .el-input__inner {
  text-align: center;
}

.SimulationTasks-panel-table .Classlist-createclass-button {
  position: absolute;
  left: 1200px;
  top: 18px;
  font-size: 20px;
  width: 130px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-size: cover;
  background: url("../../assets/img/other/icon-添加-normal.png") 100px -1px;
  background-repeat: no-repeat;
  background-size: 21%;
  -moz-background-size: 21%;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #81859c;
  cursor: pointer;
}

.SimulationTasks-panel-table .Classlist-createclass-span {
  margin-left: -15px;
  margin-bottom: 5px;
}

.SimulationTasks-panel-table .Classlist-createclass-button:hover {
  color: #0974d8;
  width: 130px;
  height: 30px;
  background: url("../../assets/img/other/icon-添加-hover.png") 100px -1px;
  background-repeat: no-repeat;
  background-size: 21%;
  -moz-background-size: 21%;
}

.SimulationTasks-panel-table i {
  font-size: 22px;
}

//各个按钮设置
.SimulationTasks-panel-tablenumber .Simulation-template-Release,
.SimulationTasks-panel-tablenumber .Simulation-template-Edit,
.SimulationTasks-panel-tablenumber .Simulation-template-result,
.SimulationTasks-panel-tablenumber .Simulation-template-finish,
.SimulationTasks-panel-tablenumber .Simulation-template-delete {
  width: 80px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid #E6E7EBFF;
  // background: rgba(255, 255, 255, 0.1);
}

.Simulation-template-stare,
.Simulation-template-studentall {
  border-radius: 10px;
  border: 1px solid #E6E7EBFF;
}

.Simulation-template-stare:hover {
  background: linear-gradient(90deg, #807DE1, #218CDE);
}

.Simulation-template-studentall:hover {
  background: linear-gradient(90deg, #807DE1, #218CDE);
}

.Simulation-template-Release:hover {
  background: linear-gradient(90deg, #807DE1, #218CDE);
  border-radius: 10px;
}

.SimulationTasks-panel-tablenumber .Simulation-template-result {
  font-size: 14px;
  color: #6581E0;
}

.SimulationTasks-panel-tablenumber .Simulation-template-delete:hover {
  background: #BF3434;
  border-radius: 10px;
  color: #ffff;
}

.SimulationTasks-panel-tablenumber .Simulation-template-result:hover {
  background: #218CDE;
  border-radius: 10px;
  color: #ffff;
}

.SimulationTasks-panel-tablenumber .Simulation-template-Edit:hover {
  background: #218CDE;
  border-radius: 10px;
  color: #ffff;
}

.SimulationTasks-panel-tablenumber .Simulation-template-finish:hover {
  background: #BF3434;
  border-radius: 10px;
  color: #ffff;
}

.SimulationTasks-panel-tablenumber .el-button:hover {
  color: #ffffff;
}

/* 表格里面滚动条设置 */
.SimulationTasks-panel-tablenumber .el-table__body-wrapper::-webkit-scrollbar {
  width: 7px;
  background-color: #f5f5f5;
}

/* 表格里面滚动条设置 */
.SimulationTasks-panel-tablenumber .el-table__body-wrapper::-webkit-scrollbar-track {
  box-shadow: inset 0 0 2px rgba(230, 232, 236, 0.3);
  border-radius: 10px;
  background-color: #f5f5f5;
}

/* 表格里面滚动条设置 */
.SimulationTasks-panel-tablenumber .el-table__body-wrapper::-webkit-scrollbar-thumb {
  border-radius: 10px;
  box-shadow: inset 0 0 2px rgba(230, 232, 236, 0.2);
  background-color: rgba(230, 232, 236, 1);
}

.CreateTask-panel {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/deep/.CreateTask-panel .el-dialog {
  width: 1200px !important;
  height: 870px;
  border-radius: 15px;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -o-user-select: none;
}

.CreateTask-panel .el-dialog__title {
  position: absolute;
  left: 20px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #81859c;
  font-size: 22px;
}

.el-dialog__headerbtn {
  font-size: 22px;
}

// .CreateTask-panel .el-input{
//   width: 50%;
// }
.CreateTask-panel .el-form-item__label {
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #81859c;
  font-size: 18px;
}

// .CreateTask-panel-one {
//   display: flex;
//   justify-content: space-around;
// }

.CreateTask-panel-one .el-form-item,
.CreateTask-panel-two .el-form-item {
  margin-bottom: 0px;
  width: 281px;
}

.taskType {
  display: flex;
}

.classTime {
  display: flex;
  margin-left: 80px;
}

.classPart {
  margin-left: 175px;
}

.dropDown {
  background-color: pink;
  width: 320px;
  height: 42px;
  border-radius: 5px;
  border: 1px solid #dadbde;
  margin-left: 12px;
}

.title-one {
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #81859c;
  font-size: 0.09375rem;
}

.title {
  margin-left: 50px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #81859c;
  font-size: 0.09375rem;
  line-height: 42px;
}

.el-input__inner {
  text-align: center;
}

.CreateTask-panel .el-form-item__content .el-input__inner {
  font-family: Source Han Sans CN;
  font-weight: 400;
  width: 100%;
  color: #81859c;
  position: relative;
  text-align: start;
}

.el-input__inner::before {
  position: absolute;
  width: 20px;
  height: 30px;
  content: "分钟";
  top: 10%;
  left: 10%;
  background: #3d8ef1;
}

s .CreateTask-panel-one,
.CreateTask-panel-two {
  display: flex;
  align-items: center;
}

.CreateTask-panel-one>div:nth-child(1) {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 778px;
  height: 42px;
}

.CreateTask-panel-one>div:nth-child(2) {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 51px;
}

.CreateTask-panel-two>div:nth-child(1) {
  display: flex;
  align-items: center;
  justify-content: center;
}

.CreateTask-panel-two>div:nth-child(2) {
  // display: flex;
  align-items: center;
  justify-content: center;
}

.CreateTask-panel-two {
  margin-top: 30px;
}

.content {
  background-color: #f3f5fb;
  width: 1200px;
  height: 531px;
  margin-left: -20px;
  margin-top: 20px;
  display: flex;
  position: relative;
  border: 1px solid #DADBDE;
}

.content-left {
  width: 300px;
  height: 100%;
}

.selectModel {
  width: 265px;
  height: 407px;
  background: #FFFFFF;
  border-radius: 5px;
  border: 1px solid #DADBDE;
  position: absolute;
  top: 93px;
  left: 28px;
  padding: 24px 19px;
  text-align: left;
}

.currentSelect {
  font-size: 18px;
  font-family: PingFangSC, PingFang SC;
  font-weight: 400;
  color: #81859c;
  margin-bottom: 13px;
  cursor: pointer;
}

.content-right {
  width: 900px;
  height: 100%;
}

.CreateTask-panel-line-one {
  margin-top: 20px;
  width: 100%;
  height: 1px;
  background: rgba(54, 56, 75, 0.2);
}

.CreateTask-panel-line-two {
  position: absolute;
  top: 204px;
  left: 200px;
  width: 1px;
  height: 60%;
  background: rgba(54, 56, 75, 0.2);
}

.CreateTask-panel-line-three {
  position: absolute;
  left: 20px;
  top: 708px;
  width: 96.5%;
  height: 1px;
  background: rgba(54, 56, 75, 0.2);
  // background: rgba(54, 56, 75, 0.2);
}

.CreateTask-panel-faultcount {
  width: 100%;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #81859c;
  font-size: 18px;
  cursor: pointer;
  margin-bottom: 13px;
}

.CreateTask-panel-faulttype {
  width: 180px;
}

.DAA {
  top: 200px;
}

.CreateTask-panel-faulttype .infinite-list {
  position: absolute;
  width: 100%;
  height: 100%;
}

.CreateTask-panel-faulttype .el-scrollbar__wrap {
  overflow-x: hidden;
}

.CreateTask-panel-faulttype .CreateTask-faulttype-moder {
  width: 100%;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #81859c;
  font-size: 16px;
  cursor: pointer;
  margin-bottom: 13px;
}

// .CreateTask-panel-faulttype .el-scrollbar__view>div:nth-last-child(1) {
//   border-bottom: 1px;
// }
.CreateTask-panel-faultpoint {
  position: absolute;
  // left: 200px;
  top: 27px;
  // top: 295px;
  width: 75%;
  height: 95%;

}

.CreateTask-panel-faultpoint .infinite-list {
  position: absolute;
  width: 100%;
  height: 100%;
}

.CreateTask-panel-faultpoint .el-scrollbar__wrap {
  overflow-x: hidden;
}

.CreateTask-panel-faultpoint .el-scrollbar__view {
  display: flex;
  flex-wrap: wrap;
}

.CreateTask-faultpoint-moder {
  width: 415px;
  height: 45px;
  line-height: 45px;
  border-radius: 5px;
  // background: rgba(129, 133, 156, 1);
  // background-color: rgba(129, 133, 156, 0.1);
  background-color: #ffffff;
  display: inline-block;
  justify-content: center;
  align-items: center;
  margin-top: 20px;
  margin-left: 20px;
  cursor: pointer;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #81859c;
  font-size: 16px;
  border: 1px solid #DADBDE;
  float: left;
}

.CreateTask-faultpoint-moder:nth-child(1) {
  margin-top: 0px;
}

.CreateTask-faultpoint-moder:nth-child(2) {
  margin-top: 0px;
}

.CreateTask-panel-two .el-form-item .CreateTask-panel-two-KaoHe {
  width: 200px;
  height: 40px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.CreateTask-panel-two-KaoHe>div:nth-child(1),
.CreateTask-panel-two-KaoHe>div:nth-child(2) {
  width: 111px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  border-radius: 5px;
  font-family: Source Han Sans CN;
  font-weight: 400;
}

.CreateTask-fault-btn {
  position: absolute;
  bottom: 30px;
  width: 100%;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.CreateTask-fault-btn .el-button {
  width: 200px;
  height: 60px;
  font-size: 20px;
  font-family: Source Han Sans CN;
  font-weight: 400;
}

.CreateTask-fault-btn .el-button:nth-child(1) {

  background: linear-gradient(-90deg, #0974d8, #3d8ef1, #7c7ff8);
  color: #FFFFFF;
}

.CreateTask-fault-btn .el-button:nth-child(2) {
  background: #81859C;
  color: #FFFFFF;
}

.CreateTask-panel-two-KaoHe-active {
  cursor: pointer;
  color: #FFFFFF !important;
  background: linear-gradient(-90deg, #0974D8, #3D8EF1, #7C7FF8) !important;
}

.CreateTask-panel-two-KaoHe-noactive {
  cursor: pointer;
  color: #FFFFFF;
  background: #81859C;
}

.CreateTask-active {
  color: #0974d8 !important;
}

.CreateTask-active::before {
  color: #0974d8;
  // position: absolute;
  // left: 96%;
  // content: '';
  // width: 7px;
  // height: 60px;
  // background: linear-gradient(-90deg, #0974D8, #3D8EF1, #7C7FF8);
  // border-radius: 5px;
  // content: none;


  // color: #7C7FF8 !important;
  // background: linear-gradient(-90deg, #0974D8, #3D8EF1, #7C7FF8);
  // background-clip: text;
  // -webkit-background-clip: text;
  // -webkit-text-fill-color: transparent;
}

.CreateTask-fault-active {
  color: #FFFFFF;
  background: linear-gradient(-90deg, #0974D8, #3D8EF1, #7C7FF8);
}

// .CreateTask-search-div .CreateTask-search-button .CreateTask-reset-button {
.CreateTask-search-button .CreateTask-reset-button {
  position: absolute;
  margin-left: 15px;
  display: inline-block;
  left: 40px;
}

.CreateTask-search-div {
  position: absolute;
  height: 42px;
  left: 28px;
  top: 27px;
  display: flex;
}

.Simulation-el-pagination {
  margin-top: 30px;
}

.CreateTask-panel .CreateTask-time-input::before {
  position: absolute;
  width: 100px;
  height: 60px;
  content: "分钟";
  top: 0px;
  left: 55px;
}

.el-select .el-input__inner {
  text-align: left;
}

/deep/.el-table th.el-table__cell>.cell {
  margin-left: 12px;
}

/deep/.el-table th.el-table__cell:last-child>.cell {
  margin-left: 0px;
}

.NameIpt {
  width: 1083px;
}
</style>
